package hu.jonas.time.client;

import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.types.Cursor;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.tab.TabSet;

public class MainWindowBuilder {

	private static HLayout mainPanel;
	private static TabSet rightPanel;
	
	private static Label createProject;
	private static Label showProjects;
	
	private static TabChangeRequestHandler tabChangeRequestHandler = new TabChangeRequestHandler();
	
	public static Widget createMainPanel() {

		mainPanel = new HLayout(5);
		mainPanel.setWidth100();
		mainPanel.setHeight100();
		
		SectionStack leftPanel = new SectionStack();
		leftPanel.setWidth(150);
		
		SectionStackSection projects = new SectionStackSection("Projects");
		projects.setExpanded(true);

		createProject = new Label("Create project");
		createProject.setCursor(Cursor.POINTER);
		createProject.addClickHandler(tabChangeRequestHandler);
		createProject.setHeight(20);
		projects.addItem(createProject);
		
		showProjects = new Label("Show projects");
		showProjects.setCursor(Cursor.POINTER);
		showProjects.addClickHandler(tabChangeRequestHandler);
		showProjects.setHeight(20);
		projects.addItem(showProjects);
		
		SectionStackSection tasks = new SectionStackSection("Tasks");
		tasks.setExpanded(true);
		
		leftPanel.addSection(projects);
		leftPanel.addSection(tasks);
		
		mainPanel.addMember(leftPanel);
		
		rightPanel = new TabSet();
		rightPanel.setWidth(600);
		rightPanel.addTab(ProjectPage.createProjectTab());
		rightPanel.addTab(ProjectPage.createProjectListTab());
		
		mainPanel.addMember(rightPanel);
		
		return mainPanel;
	}
	
	private static class TabChangeRequestHandler implements ClickHandler {

		@Override
		public void onClick(ClickEvent event) {
			
			if (event.getSource() == createProject) {
				rightPanel.setSelectedTab(0);
			}
			if (event.getSource() == showProjects) {
				rightPanel.setSelectedTab(1);
			}
			
		}
		
	}
}
